package edu.tyut.game.dao.circle;

import edu.tyut.game.model.Comment;
import org.apache.ibatis.annotations.*;

import java.util.List;

public interface CommentsDao {

    // 增
    @Insert("insert into tb_comments(username, avatar_path, fc_id, content, from_username, to_username) VALUES (#{username}, #{avatarPath}, #{fcId}, #{content}, #{fromUsername}, #{toUsername})")
    void insertComment(Comment comment);

    // 删
    @Delete("delete from tb_comments where id = #{id}")
    int deleteCommentById(int id);

    // 查
    @Select("select * from tb_comments where fc_id = #{fcId}")
    @Results({
            @Result(property = "avatarPath", column = "avatar_path"),
            @Result(property = "fcId", column = "fc_id"),
            @Result(property = "fromUsername", column = "from_username"),
            @Result(property = "toUsername", column = "to_username"),
            @Result(property = "likeCounts", column = "like_counts"),
    })
    List<Comment> getComments(int fcId);

    // 点赞 +1
    @Update("update db_game.tb_comments set like_counts = like_counts + 1 where id = #{commentId}")
    int addCommentLike(int commentId);

    // 点赞 -1
    @Update("update db_game.tb_comments set like_counts = like_counts - 1 where id = #{commentId}")
    int subCommentLike(int commentId);
}
